<!DOCTYPE html>
<html>
<head>
    <title>欢迎登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="keywords"
          content="Shadow Login Form template Responsive, Login form web template,Flat Pricing tables,Flat Drop downs  Sign up Web Templates, Flat Web Templates, Login sign up Responsive web template, SmartPhone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design"/>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);
    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    <link href="/login/css/style.css" rel="stylesheet" type="text/css" media="all"/>
    <link href="//fonts.googleapis.com/css?family=Cormorant+Garamond:300,300i,400,400i,500,500i,600,600i,700,700i"
          rel="stylesheet">
    <link href="//fonts.googleapis.com/css?family=Arsenal:400,400i,700,700i" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
</head>
<body>
<div class="main-agileinfo slider ">
    <div class="items-group">
        <div class="item agileits-w3layouts">
            <div class="block text main-agileits">
                <span class="circleLight"></span>
                <!-- 表单 -->
                <div class="login-form loginw3-agile">
                    <div class="agile-row">
                        <h1>欢迎登录</h1>
                        <div class="login-agileits-top">
                            <form action="#" method="post">
                                <p>账号</p>
                                <input type="text" class="name" id="userNumber" />
                                <p>密码</p>
                                <input type="password" class="password" id="userPassword" />
                                <p>身份</p>
                                <div style="text-align: center; ">
                                    <label style="margin-right: 20px; "><input name="userType" type="radio" value="0" checked/>用户</label>
                                    <label><input name="userType" type="radio" value="1" />管理员</label>
                                </div>
                                <input type="button" value="登录" style="margin-top: 25px; " onclick="submitLogin()" >
                            </form>
                        </div>
                        <div class="login-agileits-bottom wthree">
                            <h6><a href="/login/registerPage">暂无账号？前去注册</a></h6>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/layui/layui.js"></script>
<script>
    layui.use(['element','layer'], function(){
        let element = layui.element;
        let layer = layui.layer;

        //登录表单提交
        submitLogin = function(){
            let userNumber = $('#userNumber').val();
            let userPassword = $('#userPassword').val();
            let userType = $('input[name="userType"]:checked').val();
            if(userNumber == null || userNumber == '' || userPassword == null || userPassword == ''){
                layer.msg("请输入账号和密码！")
            }else{
                $.ajax({
                    type: "POST"
                    ,url : '/login/judgeLogin?userNumber=' + userNumber
                        + '&userPassword=' + userPassword + '&userType=' + userType
                    ,contentType: "application/json"
                    ,success : function(data) {
                        if (data === 'user') {
                            layer.msg('登录成功');
                            window.location = "/bookshop/indexPage"
                        } else if(data === 'admin'){
                            window.location = "/manager/managerUser"
                        } else if(data === 'empty'){
                            layer.msg('账号或密码错误')
                        } else {
                            layer.msg('系统发生错误,请联系管理员或稍后再试')
                        }
                    }
                });
            }
        }

    });
</script>
</body>
</html>